<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="sku" prop="sku">
        <el-input
          v-model="queryParams.sku"
          placeholder="请输入sku"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月份" prop="month">
        <el-date-picker
          v-model="queryParams.month"
          type="month"
          placeholder="选择月"
          @change="changeMonth"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>

      <div v-if="isOpen">
        <el-form-item label="月份" prop="month">
          <el-input
            v-model="queryParams.month"
            placeholder="请输入月份"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="期初数量" prop="beginningQuantity">
          <el-input
            v-model="queryParams.beginningQuantity"
            placeholder="请输入期初数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="期初金额" prop="beginningAmount">
          <el-input
            v-model="queryParams.beginningAmount"
            placeholder="请输入期初金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="期末金额" prop="endingAmount">
          <el-input
            v-model="queryParams.endingAmount"
            placeholder="请输入期末金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="期末数量" prop="endingQuantity">
          <el-input
            v-model="queryParams.endingQuantity"
            placeholder="请输入期末数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="本期成本" prop="currentPeriodCost">
          <el-input
            v-model="queryParams.currentPeriodCost"
            placeholder="请输入本期成本"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="采购退货" prop="purchaseReturnQuantity">
          <el-input
            v-model="queryParams.purchaseReturnQuantity"
            placeholder="请输入采购退货"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="采购进仓" prop="purchaseInWarehouseQuantity">
          <el-input
            v-model="queryParams.purchaseInWarehouseQuantity"
            placeholder="请输入采购进仓"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="其它进仓" prop="otherInWarehouseQuantity">
          <el-input
            v-model="queryParams.otherInWarehouseQuantity"
            placeholder="请输入其它进仓"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="其它退货" prop="otherReturnQuantity">
          <el-input
            v-model="queryParams.otherReturnQuantity"
            placeholder="请输入其它退货"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="销售出仓" prop="salesOutWarehouseQuantity">
          <el-input
            v-model="queryParams.salesOutWarehouseQuantity"
            placeholder="请输入销售出仓"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="盘点" prop="inventoryCount">
          <el-input
            v-model="queryParams.inventoryCount"
            placeholder="请输入盘点"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="加工出仓" prop="processingOutWarehouseQuantity">
          <el-input
            v-model="queryParams.processingOutWarehouseQuantity"
            placeholder="请输入加工出仓"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="调拨出" prop="transferOutQuantity">
          <el-input
            v-model="queryParams.transferOutQuantity"
            placeholder="请输入调拨出"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="销售退货" prop="salesReturnQuantity">
          <el-input
            v-model="queryParams.salesReturnQuantity"
            placeholder="请输入销售退货"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="调拨入" prop="transferInQuantity">
          <el-input
            v-model="queryParams.transferInQuantity"
            placeholder="请输入调拨入"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="其他出库" prop="otherOutWarehouseAmount">
          <el-input
            v-model="queryParams.otherOutWarehouseAmount"
            placeholder="请输入其他出库"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="本期金额" prop="currentPeriodAmount">
          <el-input
            v-model="queryParams.currentPeriodAmount"
            placeholder="请输入本期金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="销售出库金额" prop="salesOutAmount">
          <el-input
            v-model="queryParams.salesOutAmount"
            placeholder="请输入销售出库金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="销售退货金额" prop="salesReturnAmount">
          <el-input
            v-model="queryParams.salesReturnAmount"
            placeholder="请输入销售退货金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="其他出入库金额" prop="otherTransactionAmount">
          <el-input
            v-model="queryParams.otherTransactionAmount"
            placeholder="请输入其他出入库金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="盘点金额" prop="inventoryCountAmount">
          <el-input
            v-model="queryParams.inventoryCountAmount"
            placeholder="请输入盘点金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="数据-年" prop="dataYear">
          <el-input
            v-model="queryParams.dataYear"
            placeholder="请输入数据-年"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="数据-月" prop="dataMonth">
          <el-input
            v-model="queryParams.dataMonth"
            placeholder="请输入数据-月"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item> -->
      </div>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['financial:BiPurchaseSaleStock:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['financial:BiPurchaseSaleStock:edit']"
          >修改</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['financial:BiPurchaseSaleStock:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['financial:BiPurchaseSaleStock:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          size="mini"
          plain
          icon="el-icon-upload"
          @click="daoru('daoru')"
          >导入</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-show="this.roles.includes('admin')"
          size="mini"
          type="primary"
          plain
          @click="daoru('req')"
          >数据校验</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          v-show="this.roles.includes('admin')"
          size="mini"
          type="primary"
          plain
          @click="daoruData = true"
          >处理异常</el-button
        >
      </el-col> -->

      <el-col :span="4">
        <el-radio-group
          v-model="queryParams.decimalsNumber"
          size="mini"
          @change="getList"
        >
          <el-radio-button
            v-for="(item, index) in typeArr"
            :key="index"
            :label="item.value"
            >{{ item.label }}</el-radio-button
          >
        </el-radio-group>
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="BiPurchaseSaleStockList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column width="100" label="图片" align="center" prop="picUrl">
        <template slot-scope="scope">
          <image-preview-full
            :src="scope.row.picUrl"
            :width="30"
            :height="30"
          />
        </template>
      </el-table-column>
      <el-table-column
        width="100"
        label="分类"
        align="center"
        prop="category"
      />
      <el-table-column
        width="100"
        label="虚拟分类"
        align="center"
        prop="virtualCategory"
      />
      <el-table-column
        width="100"
        label="款式编码"
        align="center"
        prop="productNo"
      />
      <el-table-column width="120" label="sku" align="center" prop="sku" />
      <el-table-column
        width="100"
        label="商品名称"
        align="center"
        prop="productName"
      />
      <el-table-column
        width="100"
        label="商品简称"
        align="center"
        prop="productShortName"
      />
      <!-- <el-table-column
        width="100"
        label="供应商款号"
        align="center"
        prop="supplierStyleNumber"
      />
      <el-table-column
        width="100"
        label="供应商商品编码"
        align="center"
        prop="supplierProductCode"
      /> -->
      <el-table-column
        width="100"
        label="颜色规格"
        align="center"
        prop="colorSpecification"
      />
      <el-table-column width="100" label="品牌" align="center" prop="brand" />
      <el-table-column width="100" label="重量" align="center" prop="weight" />
      <!-- <el-table-column width="100" label="体积" align="center" prop="volume" />
      <el-table-column width="100" label="长" align="center" prop="length" />
      <el-table-column width="100" label="宽" align="center" prop="width" />
      <el-table-column width="100" label="高" align="center" prop="height" />
      <el-table-column
        width="100"
        label="出入库"
        align="center"
        prop="inOutQuantity"
      /> -->

      <el-table-column
        width="100"
        label="期初数量"
        align="center"
        prop="beginningQuantity"
      />
      <el-table-column
        width="100"
        label="加工进仓"
        align="center"
        prop="processingQuantity"
      />
      <el-table-column
        width="100"
        label="采购退货"
        align="center"
        prop="purchaseReturnQuantity"
      />
      <el-table-column
        width="100"
        label="采购进仓"
        align="center"
        prop="purchaseInWarehouseQuantity"
      />
      <el-table-column
        width="100"
        label="其它进仓"
        align="center"
        prop="otherInWarehouseQuantity"
      />
      <el-table-column
        width="100"
        label="其它退货"
        align="center"
        prop="otherReturnQuantity"
      />
      <el-table-column
        width="100"
        label="销售出仓"
        align="center"
        prop="salesOutWarehouseQuantity"
      />
      <el-table-column
        width="100"
        label="盘点"
        align="center"
        prop="inventoryCount"
      />
      <el-table-column
        width="100"
        label="加工出仓"
        align="center"
        prop="processingOutWarehouseQuantity"
      />
      <el-table-column
        width="100"
        label="调拨出"
        align="center"
        prop="transferOutQuantity"
      />
      <el-table-column
        width="100"
        label="销售退货"
        align="center"
        prop="salesReturnQuantity"
      />
      <el-table-column
        width="100"
        label="调拨入"
        align="center"
        prop="transferInQuantity"
      />
      <el-table-column
        width="100"
        label="其他出库"
        align="center"
        prop="otherOutWarehouseAmount"
      />
      <el-table-column
        width="100"
        label="期末数量"
        align="center"
        prop="endingQuantity"
      />
      <el-table-column
        width="100"
        label="库存周转天数"
        align="center"
        prop="inventoryTurnoverDays"
      />
      <el-table-column
        width="100"
        label="成本价"
        align="center"
        prop="currentPeriodCostOrg"
      />
      <el-table-column
        width="100"
        label="期初金额"
        align="center"
        prop="beginningAmountOrg"
      />
      <el-table-column
        width="100"
        label="期末金额"
        align="center"
        prop="endingAmountOrg"
      />

      <el-table-column
        width="100"
        label="本期成本"
        align="center"
        prop="currentPeriodCost"
      />
      <el-table-column
        width="120"
        label="期初+采购金额"
        align="center"
        prop="currentPeriodAmount"
      />
      <el-table-column
        width="120"
        label="销售出库金额"
        align="center"
        prop="salesOutAmount"
      />
      <el-table-column
        width="120"
        label="销售退货金额"
        align="center"
        prop="salesReturnAmount"
      />
      <el-table-column
        width="120"
        label="其他出入库金额"
        align="center"
        prop="otherTransactionAmount"
      />
      <el-table-column
        width="120"
        label="盘点金额"
        align="center"
        prop="inventoryCountAmount"
      />
      <el-table-column
        width="120"
        label="计算期初金额"
        align="center"
        prop="beginningAmount"
      />
      <el-table-column
        width="120"
        label="计算期末金额"
        align="center"
        prop="endingAmount"
      />
      <!-- <el-table-column  width="120" label="月成本表id" align="center" prop="id" /> -->

      <!-- <el-table-column
        width="120"
        label="计算成本价"
        align="center"
        prop="currentPeriodCost"
      /> -->

      <el-table-column width="100" label="月份" align="center" prop="month" />
      <el-table-column
        width="100"
        label="数据-年"
        align="center"
        prop="dataYear"
      />
      <el-table-column
        width="100"
        label="数据-月"
        align="center"
        prop="dataMonth"
      />

      <el-table-column
        width="100"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['financial:BiPurchaseSaleStock:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['financial:BiPurchaseSaleStock:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改月度进销存对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="sku" prop="sku">
          <el-input v-model="form.sku" placeholder="请输入sku" />
        </el-form-item>
        <el-form-item label="月份" prop="month">
          <el-input v-model="form.month" placeholder="请输入月份" />
        </el-form-item>
        <el-form-item label="期初数量" prop="beginningQuantity">
          <el-input
            v-model="form.beginningQuantity"
            placeholder="请输入期初数量"
          />
        </el-form-item>
        <el-form-item label="期初金额" prop="beginningAmount">
          <el-input
            v-model="form.beginningAmount"
            placeholder="请输入期初金额"
          />
        </el-form-item>
        <el-form-item label="期末金额" prop="endingAmount">
          <el-input v-model="form.endingAmount" placeholder="请输入期末金额" />
        </el-form-item>
        <el-form-item label="期末数量" prop="endingQuantity">
          <el-input
            v-model="form.endingQuantity"
            placeholder="请输入期末数量"
          />
        </el-form-item>
        <el-form-item label="本期成本" prop="currentPeriodCost">
          <el-input
            v-model="form.currentPeriodCost"
            placeholder="请输入本期成本"
          />
        </el-form-item>
        <el-form-item label="采购退货" prop="purchaseReturnQuantity">
          <el-input
            v-model="form.purchaseReturnQuantity"
            placeholder="请输入采购退货"
          />
        </el-form-item>
        <el-form-item label="采购进仓" prop="purchaseInWarehouseQuantity">
          <el-input
            v-model="form.purchaseInWarehouseQuantity"
            placeholder="请输入采购进仓"
          />
        </el-form-item>
        <el-form-item label="其它进仓" prop="otherInWarehouseQuantity">
          <el-input
            v-model="form.otherInWarehouseQuantity"
            placeholder="请输入其它进仓"
          />
        </el-form-item>
        <el-form-item label="其它退货" prop="otherReturnQuantity">
          <el-input
            v-model="form.otherReturnQuantity"
            placeholder="请输入其它退货"
          />
        </el-form-item>
        <el-form-item label="销售出仓" prop="salesOutWarehouseQuantity">
          <el-input
            v-model="form.salesOutWarehouseQuantity"
            placeholder="请输入销售出仓"
          />
        </el-form-item>
        <el-form-item label="盘点" prop="inventoryCount">
          <el-input v-model="form.inventoryCount" placeholder="请输入盘点" />
        </el-form-item>
        <el-form-item label="加工出仓" prop="processingOutWarehouseQuantity">
          <el-input
            v-model="form.processingOutWarehouseQuantity"
            placeholder="请输入加工出仓"
          />
        </el-form-item>
        <el-form-item label="调拨出" prop="transferOutQuantity">
          <el-input
            v-model="form.transferOutQuantity"
            placeholder="请输入调拨出"
          />
        </el-form-item>
        <el-form-item label="销售退货" prop="salesReturnQuantity">
          <el-input
            v-model="form.salesReturnQuantity"
            placeholder="请输入销售退货"
          />
        </el-form-item>
        <el-form-item label="调拨入" prop="transferInQuantity">
          <el-input
            v-model="form.transferInQuantity"
            placeholder="请输入调拨入"
          />
        </el-form-item>
        <el-form-item label="其他出库" prop="otherOutWarehouseAmount">
          <el-input
            v-model="form.otherOutWarehouseAmount"
            placeholder="请输入其他出库"
          />
        </el-form-item>
        <el-form-item label="本期金额" prop="currentPeriodAmount">
          <el-input
            v-model="form.currentPeriodAmount"
            placeholder="请输入本期金额"
          />
        </el-form-item>
        <el-form-item label="销售出库金额" prop="salesOutAmount">
          <el-input
            v-model="form.salesOutAmount"
            placeholder="请输入销售出库金额"
          />
        </el-form-item>
        <el-form-item label="销售退货金额" prop="salesReturnAmount">
          <el-input
            v-model="form.salesReturnAmount"
            placeholder="请输入销售退货金额"
          />
        </el-form-item>
        <el-form-item label="其他出入库金额" prop="otherTransactionAmount">
          <el-input
            v-model="form.otherTransactionAmount"
            placeholder="请输入其他出入库金额"
          />
        </el-form-item>
        <el-form-item label="盘点金额" prop="inventoryCountAmount">
          <el-input
            v-model="form.inventoryCountAmount"
            placeholder="请输入盘点金额"
          />
        </el-form-item>
        <el-form-item label="数据-年" prop="dataYear">
          <el-input v-model="form.dataYear" placeholder="请输入数据-年" />
        </el-form-item>
        <el-form-item label="数据-月" prop="dataMonth">
          <el-input v-model="form.dataMonth" placeholder="请输入数据-月" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改产品二级信息对话框 :on-change="handleChange"-->
    <el-dialog
      title="导入"
      :visible.sync="dialogVisible"
      width="500px"
      append-to-body
      v-if="dialogVisible"
    >
      <!-- 文件上传-->
      <el-form
        :rules="rules"
        :model="dataForm"
        ref="dataForm"
        label-width="150px"
        @submit.native.prevent
      >
        <el-form-item label="" prop="name">
          <el-date-picker
            v-model="dataForm.name"
            type="month"
            placeholder="选择月"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="文件：" prop="file">
          <el-upload
            class="upload-import"
            ref="uploadImport"
            :http-request="httpRequest"
            action=""
            :on-remove="handleRemove"
            :file-list="fileList"
            :limit="1"
            :on-change="handleChange"
            :auto-upload="false"
            :before-upload="beforeAvatarUpload"
          >
            <!--
            accept="application/zip,.zip" 设置接收的文件类型-->
            <el-button
              v-show="!hasFile"
              slot="trigger"
              size="small"
              type="primary"
              >选取文件</el-button
            >
            <!-- <div slot="tip" class="el-upload__tip">
          只能上传zip文件，且不超过10M
        </div> -->
          </el-upload>
          <!-- 关闭自动上传-->
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitUpload">提交</el-button>
          <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
          <el-button @click="dialogVisible = false">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 添加或修改产品二级信息对话框 :on-change="handleChange"-->
    <el-dialog
      title="导入"
      :visible.sync="daoruData"
      width="500px"
      append-to-body
      v-if="daoruData"
    >
      <!-- 文件上传-->
      <el-form :model="daoruDataForm" label-width="150px">
        <el-form-item label="" prop="name">
          <el-date-picker
            v-model="daoruDataForm.name"
            type="month"
            placeholder="选择月"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitDataForm">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      append-to-body
      :visible.sync="openAfter"
      width="1800px"
      v-if="openAfter"
    >
      <financialCheckvue @deleteAll="deleteAll" />
    </el-dialog>
  </div>
</template>

<script>
import financialCheckvue from "@/views/financial/financialCheck/index.vue";
import After from "@/views/conf/After/propsTableName.vue";
import {
  listBiPurchaseSaleStock,
  getBiPurchaseSaleStock,
  delBiPurchaseSaleStock,
  addBiPurchaseSaleStock,
  updateBiPurchaseSaleStock,
  secondPurchaseSaleStock,
  financialCheck,
  CheckdeleteAll,
  processCheck,
} from "@/api/financial/BiPurchaseSaleStock";
import axios from "axios";
//--------导入token
import { getToken } from "@/utils/auth";
import moment from "moment";
import { getInfo } from "@/api/login.js";
export default {
  name: "BiPurchaseSaleStock",
  components: {
    After,
    financialCheckvue,
  },

  data() {
    return {
      tableName: "",
      openAfter: false,
      type: "",
      typeArr: [
        { value: 2, label: "小数点后两位" },
        { value: 6, label: "小数点后六位" },
      ],
      daoruDataForm: {
        name: "",
      },
      daoruData: false,

      //文件
      dataForm: {
        name: "",
        file: null,
      },
      hasFile: false,
      fileList: [],
      dialogVisible: false,
      pjtUrl: process.env.VUE_APP_BASE_API,
      isOpen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 月度进销存表格数据
      BiPurchaseSaleStockList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        decimalsNumber: 2,
        sku: null,
        month: null,
        beginningQuantity: null,
        beginningAmount: null,
        endingAmount: null,
        endingQuantity: null,
        currentPeriodCost: null,
        purchaseReturnQuantity: null,
        purchaseInWarehouseQuantity: null,
        otherInWarehouseQuantity: null,
        otherReturnQuantity: null,
        salesOutWarehouseQuantity: null,
        inventoryCount: null,
        processingOutWarehouseQuantity: null,
        transferOutQuantity: null,
        salesReturnQuantity: null,
        transferInQuantity: null,
        otherOutWarehouseAmount: null,
        currentPeriodAmount: null,
        salesOutAmount: null,
        salesReturnAmount: null,
        otherTransactionAmount: null,
        inventoryCountAmount: null,
        dataYear: null,
        dataMonth: null,
      },
      roles: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sku: [{ required: true, message: "sku不能为空", trigger: "blur" }],
        month: [{ required: true, message: "月份不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
    this.getroles();
  },

  methods: {
    getroles() {
      // var userId = null
      getInfo().then((res) => {
        //当前操作用户角色
        this.roles = res.roles;
        // log;
      });
    },
    deleteAll() {
      CheckdeleteAll().then((response) => {});
    },
    changeMonth() {
      let parts = moment(this.queryParams.month).format("yyyy-MM").split("-");
      this.queryParams.dataYear = parts[0];
      this.queryParams.dataMonth = parts[1];
    },
    //二级计算
    submitDataForm() {
      this.daoruDataForm.name = moment(this.daoruDataForm.name).format(
        "YYYY-MM"
      );
      let fd = new FormData();
      fd.append("dataYear", this.daoruDataForm.name.split("-")[0]);
      fd.append("dataMonth", this.daoruDataForm.name.split("-")[1]);
      // let obj = {
      //   dataYear: this.daoruDataForm.name.split("-")[0],
      //   dataMonth: this.daoruDataForm.name.split("-")[1],
      // };
      // this.openLoading();
      processCheck(fd).then((response) => {
        if (response.code == 200) {
          // this.$modal.closeLoading();

          this.daoruData = false;
          if (this.type == "req") {
            this.$modal.msgSuccess("数据校验完毕,暂时别关闭页面");
            this.tableName = "finance_inventory_check";
            this.openAfter = true;
          }
          this.getList();
        }
      });
    },
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      // const isJPG = file.type == 'image/jpeg' || file.type == 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 100;
      // if (!isJPG) {
      //     this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error("上传导入文件大小不能超过 100MB!");
      }

      return isLt2M;
    },
    handleRemove(file, fileList) {
      if (!fileList.length) {
        this.hasFile = false;
      }
      this.dataForm.file = null;
    },
    handleChange(file, fileList) {
      if (fileList.length >= 2) {
        return;
      }
      if (fileList.length === 1) {
        this.hasFile = true;
      }
      this.dataForm.file = file;
    },
    //确定按钮
    //调用组件upload的submit方法，从而触发httpRequest方法，实现手动上传
    submitUpload() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.$refs.uploadImport.submit();
        }
      });
    },
    httpRequest(param) {
      // if (this.dataForm.name.length < 3) {
      //   this.$modal.msgWarning("请选择到店铺");
      //   return;
      // }
      this.daoruDataForm.name = this.dataForm.name;
      this.dataForm.name = moment(this.dataForm.name).format("YYYY-MM");
      let fd = new FormData();
      fd.append("file", param.file); // 传文件
      fd.append("dataYear", this.dataForm.name.split("-")[0]);
      fd.append("dataMonth", this.dataForm.name.split("-")[1]);
      //dataPar.file.raw

      //
      console.log(JSON.stringify(fd));
      let url;
      if (this.type == "daoru") {
        url =
          process.env.VUE_APP_BASE_API +
          "/financial/BiPurchaseSaleStock/importData";
      } else if (this.type == "req") {
        url = process.env.VUE_APP_BASE_API + "/financial/financialCheck/check";
      }
      this.openLoading();
      axios
        .post(url, fd, {
          headers: {
            header: { responseType: "blob" },

            Authorization: "Bearer " + getToken(),
            "Content-Type": "multipart/form-data",
          }, //定义内容格式,很重要
          // timeout: 20000,
        })
        .then((response) => {
          console.log(response);
          this.dialogVisible = false;
          if (response.data.code == 200) {
            this.$modal.closeLoading();
            this.$modal.msgSuccess("导入成功");
            this.hasFile = false;
            //处理异常
            this.submitDataForm();

            this.getList();
          }
        });
    },
    //部门文件导入修改打开
    daoru(type) {
      this.type = type;
      this.dialogVisible = true;
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在导入，请稍候！");
    },
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询月度进销存列表 */
    getList() {
      this.loading = true;
      listBiPurchaseSaleStock(this.queryParams).then((response) => {
        this.BiPurchaseSaleStockList = response.rows ? response.rows : [];
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sku: null,
        month: null,
        beginningQuantity: null,
        beginningAmount: null,
        endingAmount: null,
        endingQuantity: null,
        currentPeriodCost: null,
        purchaseReturnQuantity: null,
        purchaseInWarehouseQuantity: null,
        otherInWarehouseQuantity: null,
        otherReturnQuantity: null,
        salesOutWarehouseQuantity: null,
        inventoryCount: null,
        processingOutWarehouseQuantity: null,
        transferOutQuantity: null,
        salesReturnQuantity: null,
        transferInQuantity: null,
        otherOutWarehouseAmount: null,
        currentPeriodAmount: null,
        salesOutAmount: null,
        salesReturnAmount: null,
        otherTransactionAmount: null,
        inventoryCountAmount: null,
        dataYear: null,
        dataMonth: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {};
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加月度进销存";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiPurchaseSaleStock(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改月度进销存";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiPurchaseSaleStock(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiPurchaseSaleStock(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除月度进销存编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiPurchaseSaleStock(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "financial/BiPurchaseSaleStock/export",
        {
          ...this.queryParams,
        },
        `BiPurchaseSaleStock_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
